package com.base.myproject.client.HR.Salary;

import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.BaseOpenJSP;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Label;

/**
 * @author cxghiu410@gmail.com
 *	薪金对比
 */
public class Rpt_SalaryContrast extends BaseJDBCPanel {
	BaseComboBoxForm<BaseModelData> before = new BaseComboBoxForm<BaseModelData>("icode","code","hr_salary_main_c","where exists (select * from hr_salary where hr_salary.upcode = hr_salary_main_c.code)",true);
	BaseComboBoxForm<BaseModelData> after = new BaseComboBoxForm<BaseModelData>("icode","code","hr_salary_main_c","where exists (select * from hr_salary where hr_salary.upcode = hr_salary_main_c.code)",true);
	Button search = new Button("查询");
	String jspFile = "hr_Jsp/rptSalaryContrast.jsp";  //默认的JSP页面
	public Rpt_SalaryContrast() {
		init();
	}
	
	public void complete() {
		super.complete();
		print.addListener(Events.OnClick, getListener());
		getToolbarll().add(print);
	}
	
	BaseOpenJSP jsp;
	protected void init() {
		search.addListener(Events.OnClick, getListener());
		VerticalPanel vp = new VerticalPanel();
		HorizontalPanel hp = new HorizontalPanel();
		hp.setSpacing(10);
		hp.add(new Label("对比前编码："));
		hp.add(before);
		hp.add(new Label("对比后编码："));
		hp.add(after);
		hp.add(search);
		
		vp.add(hp);
		jsp = new BaseOpenJSP(jspFile);
		Tools.setResize(jsp, 0.99, 0.89);
		vp.add(jsp);
		add(vp);
	}

	Listener<BaseEvent> listener;
	private Listener<? extends BaseEvent> getListener() {
		if (listener != null) 
			return listener;
		listener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				if (be.getSource().equals(search)) {
					if (before.getValue() == null && after.getValue() == null) {
						MessageBox.alert("提示", "请选择要进行薪金对比的两个编码，谢谢", null);
						return;
					}
					jsp.getFrame().setUrl(jspFile + "?beforeIcode=" + before.getValue().get("code") + "&afterIcode=" + after.getValue().get("code"));
				} else {
					jsp.Print();
				}
			}
		};
		return listener;
	}
}
